#!/usr/bin/env python
# -*- coding: utf8 -*-

from fpdf import FPDF
from fpdf.tablepdf import TablePdf
import sys

fn = 'tables.pdf'

pdf = FPDF()
pdf.add_page()
pdf.set_font('Arial','',12)
pdf.set_fill_color(80, 80, 80)


table = TablePdf(pdf).defineTable([20, 20, 20, 100], 5)
table[0,0] = "row=0, col=0"
table[0,1] = "row=0, col=1"
table[0,2] = "row=0, col=2"
table[1,0] = "row=1, col=0"
table[1,1] = "row=1, col=1"
table[1,2] = "row=1, col=2"
table[2,1] = "very long content to show that table is bigger"
table[3,3] = "biggest column in this table"
table.drawTable(10, 10)


# table without header
table = TablePdf(pdf).defineTable([10, 20, 15, 40], 3, header=False)
table[0,0] = "row=0, col=0"
table[0,1] = "row=0, col=1"
table[0,2] = "row=0, col=2"
table[1,0] = "row=1, col=0"
table[1,1] = "row=1, col=1"
table[1,2] = "row=1, col=2"
table[2,1] = "very long content to show that table is bigger"
table[2,3] = "biggest column in this table"
table.drawTable(20, pdf.get_y()+5)


pdf.output(fn,'F')
import os
try:
    os.startfile(fn)
except:
    os.system("evince %s" % fn)

